home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / overview / moreisbetter / mib-libraries / moredevices / interruptsafedebug / interruptsafedebug.c next >
Encoding:
Text File  |  2000-06-23  |  23.9 KB  |  335 lines

  1. /*
  2.     File:        InterruptSafeDebug.c
  3.  
  4.     Contains:    Library for logging directly to the screen.
  5.  
  6.     Written by:    Quinn "The Eskimo!"
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.  
  20.          <1>    23/11/98    Quinn   First checked in.
  21. */
  22.  
  23. /////////////////////////////////////////////////////////////////////
  24.  
  25. // Setup MoreIsBetter environment
  26.  
  27. #include "MoreSetup.h"
  28.  
  29. // Standard Mac OS interfaces
  30.  
  31. #include <DriverSynchronization.h>
  32. #include <QuickDraw.h>
  33. #include <QDOffscreen.h>
  34. #include <OpenTransport.h>
  35. #include <CodeFragments.h>
  36. #include <Gestalt.h>
  37.  
  38. // Our prototypes
  39.  
  40. #include "InterruptSafeDebug.h"
  41.  
  42. /////////////////////////////////////////////////////////////////////
  43.  
  44. // This font data was generated by the GenerateFont program, the
  45. // source of which is included in the sample.  Each row contains
  46. // 256 bytes, one for each character in the font.  The rows represent
  47. // the scanline in the character.
  48.  
  49. static UInt8 gFont[10][256] = {
  50.     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x00, 0x3c, 0x3c, 0x3c, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x10, 0x28, 0x28, 0x38, 0x3c, 0x30, 0x10, 0x08, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x04, 0x38, 0x08, 0x38, 0x38, 0x08, 0x7c, 0x38, 0x7c, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x78, 0x38, 0x78, 0x7c, 0x7c, 0x38, 0x44, 0x10, 0x04, 0x44, 0x40, 0x44, 0x44, 0x38, 0x78, 0x38, 0x78, 0x38, 0x7c, 0x44, 0x44, 0x44, 0x44, 0x44, 0x7c, 0x18, 0x20, 0x18, 0x10, 0x00, 0x10, 0x00, 0x40, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x40, 0x10, 0x10, 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x34, 0x00, 0x38, 0x38, 0x38, 0x7c, 0x44, 0x38, 0x44, 0x10, 0x08, 0x28, 0x28, 0x58, 0x24, 0x00, 0x10, 0x10, 0x28, 0x28, 0x10, 0x10, 0x28, 0x28, 0x58, 0x10, 0x10, 0x28, 0x28, 0x58, 0x10, 0x10, 0x28, 0x28, 0x10, 0x24, 0x00, 0x48, 0x24, 0x00, 0x54, 0x24, 0x70, 0x70, 0x7a, 0x08, 0x28, 0x00, 0x3c, 0x38, 0x00, 0x00, 0x08, 0x10, 0x44, 0x00, 0x10, 0x7c, 0x7c, 0x00, 0x10, 0x1c, 0x18, 0x38, 0x00, 0x00, 0x10, 0x08, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x3c, 0x00, 0x00, 0x00, 0x14, 0x14, 0x08, 0x18, 0x00, 0x00, 0x28, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c},
  51.     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x24, 0x00, 0x24, 0x24, 0x24, 0x00, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x10, 0x28, 0x7c, 0x54, 0x54, 0x48, 0x10, 0x10, 0x08, 0x54, 0x10, 0x00, 0x00, 0x00, 0x04, 0x44, 0x18, 0x44, 0x44, 0x18, 0x40, 0x40, 0x04, 0x44, 0x44, 0x00, 0x00, 0x08, 0x00, 0x20, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x40, 0x40, 0x44, 0x44, 0x10, 0x04, 0x48, 0x40, 0x6c, 0x64, 0x44, 0x44, 0x44, 0x44, 0x44, 0x10, 0x44, 0x44, 0x44, 0x28, 0x44, 0x04, 0x10, 0x20, 0x08, 0x28, 0x00, 0x08, 0x00, 0x40, 0x00, 0x04, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x58, 0x00, 0x44, 0x44, 0x44, 0x40, 0x64, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x24, 0x10, 0x40, 0x50, 0x38, 0x54, 0x44, 0x08, 0x08, 0x2e, 0x10, 0x00, 0x08, 0x50, 0x44, 0x00, 0x10, 0x10, 0x08, 0x28, 0x00, 0x08, 0x24, 0x28, 0x00, 0x10, 0x24, 0x24, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x10, 0x04, 0x10, 0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x50, 0x00, 0x00, 0x00, 0x28, 0x14, 0x10, 0x08, 0x10, 0x10, 0x00, 0x7e, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24},
  52.     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x24, 0x00, 0x24, 0x24, 0x24, 0x00, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x10, 0x00, 0x28, 0x50, 0x58, 0x50, 0x00, 0x20, 0x04, 0x38, 0x10, 0x00, 0x00, 0x00, 0x08, 0x44, 0x08, 0x04, 0x04, 0x28, 0x78, 0x78, 0x04, 0x44, 0x44, 0x10, 0x10, 0x10, 0x7c, 0x10, 0x04, 0x74, 0x44, 0x44, 0x40, 0x44, 0x40, 0x40, 0x40, 0x44, 0x10, 0x04, 0x50, 0x40, 0x54, 0x54, 0x44, 0x44, 0x44, 0x44, 0x40, 0x10, 0x44, 0x44, 0x44, 0x10, 0x44, 0x08, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00, 0x3c, 0x78, 0x38, 0x3c, 0x38, 0x38, 0x3c, 0x78, 0x10, 0x10, 0x48, 0x10, 0x78, 0x58, 0x38, 0x78, 0x3c, 0x58, 0x3c, 0x38, 0x44, 0x44, 0x54, 0x44, 0x44, 0x7c, 0x08, 0x10, 0x10, 0x00, 0x00, 0x44, 0x44, 0x40, 0x40, 0x54, 0x44, 0x44, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x38, 0x38, 0x38, 0x38, 0x38, 0x10, 0x10, 0x10, 0x10, 0x58, 0x38, 0x38, 0x38, 0x38, 0x38, 0x44, 0x44, 0x44, 0x44, 0x10, 0x18, 0x38, 0x70, 0x48, 0x7c, 0x54, 0x48, 0x64, 0x34, 0x2e, 0x00, 0x00, 0x7c, 0x50, 0x4c, 0x6c, 0x10, 0x20, 0x04, 0x7c, 0x48, 0x0c, 0x10, 0x28, 0x7c, 0x10, 0x24, 0x24, 0x44, 0x38, 0x38, 0x10, 0x08, 0x00, 0x08, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x50, 0x28, 0x00, 0x00, 0x28, 0x28, 0x18, 0x10, 0x00, 0x28, 0x44, 0x00, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24},
  53.     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x24, 0x00, 0x24, 0x24, 0x24, 0x00, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x10, 0x00, 0x7c, 0x38, 0x28, 0x20, 0x00, 0x20, 0x04, 0x54, 0x7c, 0x00, 0x7c, 0x00, 0x08, 0x44, 0x08, 0x08, 0x18, 0x48, 0x04, 0x44, 0x08, 0x38, 0x44, 0x00, 0x00, 0x20, 0x00, 0x08, 0x08, 0x54, 0x7c, 0x78, 0x40, 0x44, 0x78, 0x78, 0x4c, 0x7c, 0x10, 0x04, 0x60, 0x40, 0x44, 0x4c, 0x44, 0x78, 0x44, 0x78, 0x38, 0x10, 0x44, 0x44, 0x44, 0x10, 0x28, 0x10, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x44, 0x10, 0x44, 0x44, 0x10, 0x10, 0x50, 0x10, 0x54, 0x64, 0x44, 0x44, 0x44, 0x64, 0x40, 0x10, 0x44, 0x44, 0x54, 0x28, 0x44, 0x08, 0x10, 0x10, 0x08, 0x00, 0x00, 0x7c, 0x7c, 0x40, 0x78, 0x4c, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x10, 0x10, 0x10, 0x10, 0x64, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x10, 0x00, 0x54, 0x40, 0x24, 0x7c, 0x3c, 0x48, 0x54, 0x44, 0x00, 0x00, 0x00, 0x10, 0x78, 0x54, 0x54, 0x7c, 0x10, 0x08, 0x10, 0x48, 0x14, 0x08, 0x28, 0x28, 0x10, 0x1c, 0x18, 0x44, 0x54, 0x4c, 0x20, 0x08, 0x7c, 0x10, 0x10, 0x44, 0x28, 0x24, 0x48, 0x00, 0x00, 0x7c, 0x7c, 0x44, 0x58, 0x54, 0x38, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x44, 0x44, 0x7e, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24},
  54.     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x24, 0x00, 0x24, 0x24, 0x24, 0x00, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x10, 0x00, 0x28, 0x14, 0x34, 0x54, 0x00, 0x20, 0x04, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10, 0x44, 0x08, 0x10, 0x04, 0x7c, 0x04, 0x44, 0x10, 0x44, 0x3c, 0x00, 0x00, 0x10, 0x7c, 0x10, 0x10, 0x78, 0x44, 0x44, 0x40, 0x44, 0x40, 0x40, 0x44, 0x44, 0x10, 0x44, 0x50, 0x40, 0x44, 0x44, 0x44, 0x40, 0x44, 0x44, 0x04, 0x10, 0x44, 0x44, 0x54, 0x10, 0x10, 0x20, 0x10, 0x08, 0x08, 0x00, 0x00, 0x00, 0x44, 0x44, 0x40, 0x44, 0x7c, 0x10, 0x44, 0x44, 0x10, 0x10, 0x70, 0x10, 0x54, 0x44, 0x44, 0x44, 0x44, 0x40, 0x38, 0x10, 0x44, 0x44, 0x54, 0x10, 0x44, 0x10, 0x08, 0x10, 0x10, 0x00, 0x00, 0x44, 0x44, 0x40, 0x40, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x40, 0x7c, 0x7c, 0x7c, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x10, 0x00, 0x50, 0x40, 0x14, 0x7c, 0x14, 0x44, 0x64, 0x34, 0x00, 0x00, 0x00, 0x7c, 0x50, 0x64, 0x6c, 0x10, 0x08, 0x10, 0x7c, 0x48, 0x24, 0x10, 0x28, 0x28, 0x10, 0x00, 0x00, 0x44, 0x5c, 0x54, 0x40, 0x08, 0x04, 0x50, 0x10, 0x38, 0x28, 0x48, 0x24, 0x00, 0x00, 0x44, 0x44, 0x44, 0x50, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x44, 0x00, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24},
  55.     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x24, 0x00, 0x24, 0x24, 0x24, 0x00, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x54, 0x54, 0x48, 0x00, 0x10, 0x08, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x44, 0x08, 0x20, 0x44, 0x08, 0x44, 0x44, 0x10, 0x44, 0x04, 0x00, 0x00, 0x08, 0x00, 0x20, 0x00, 0x40, 0x44, 0x44, 0x44, 0x44, 0x40, 0x40, 0x44, 0x44, 0x10, 0x44, 0x48, 0x40, 0x44, 0x44, 0x44, 0x40, 0x44, 0x44, 0x44, 0x10, 0x44, 0x28, 0x6c, 0x28, 0x10, 0x40, 0x10, 0x08, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x44, 0x40, 0x44, 0x40, 0x10, 0x44, 0x44, 0x10, 0x10, 0x48, 0x10, 0x54, 0x44, 0x44, 0x44, 0x44, 0x40, 0x04, 0x10, 0x4c, 0x28, 0x54, 0x28, 0x44, 0x20, 0x08, 0x10, 0x10, 0x00, 0x00, 0x44, 0x44, 0x44, 0x40, 0x44, 0x44, 0x44, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x10, 0x10, 0x10, 0x10, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x4c, 0x4c, 0x4c, 0x4c, 0x00, 0x00, 0x54, 0x44, 0x48, 0x38, 0x14, 0x44, 0x58, 0x08, 0x00, 0x00, 0x00, 0x20, 0x50, 0x44, 0x00, 0x10, 0x00, 0x00, 0x10, 0x48, 0x24, 0x24, 0x28, 0x28, 0x10, 0x3c, 0x3c, 0x28, 0x50, 0x64, 0x44, 0x08, 0x04, 0x20, 0x10, 0x40, 0x44, 0x48, 0x24, 0x00, 0x00, 0x44, 0x44, 0x44, 0x50, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x44, 0x7e, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24},
  56.     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x00, 0x3c, 0x3c, 0x3c, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x38, 0x48, 0x34, 0x00, 0x08, 0x10, 0x00, 0x00, 0x10, 0x00, 0x10, 0x20, 0x38, 0x08, 0x7c, 0x38, 0x08, 0x38, 0x38, 0x10, 0x38, 0x38, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10, 0x38, 0x44, 0x78, 0x38, 0x78, 0x7c, 0x40, 0x38, 0x44, 0x10, 0x38, 0x44, 0x7c, 0x44, 0x44, 0x38, 0x40, 0x38, 0x44, 0x38, 0x10, 0x38, 0x10, 0x44, 0x44, 0x10, 0x7c, 0x18, 0x04, 0x18, 0x00, 0x7e, 0x00, 0x34, 0x78, 0x3c, 0x3c, 0x3c, 0x10, 0x3c, 0x44, 0x10, 0x10, 0x44, 0x10, 0x54, 0x44, 0x38, 0x78, 0x3c, 0x40, 0x78, 0x0c, 0x34, 0x10, 0x28, 0x44, 0x3c, 0x7c, 0x08, 0x10, 0x10, 0x00, 0x00, 0x44, 0x44, 0x38, 0x7c, 0x44, 0x38, 0x38, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x10, 0x10, 0x10, 0x10, 0x44, 0x38, 0x38, 0x38, 0x38, 0x38, 0x34, 0x34, 0x34, 0x34, 0x00, 0x00, 0x38, 0x78, 0x44, 0x00, 0x14, 0x58, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x38, 0x00, 0x7c, 0x38, 0x1c, 0x10, 0x74, 0x18, 0x7c, 0x28, 0x28, 0x10, 0x00, 0x00, 0x6c, 0x3c, 0x38, 0x38, 0x08, 0x00, 0x20, 0x10, 0x00, 0x7c, 0x24, 0x48, 0x54, 0x00, 0x44, 0x44, 0x38, 0x3c, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c},
  57.     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x38, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  58.     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  59.     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
  60. };
  61.  
  62. static UInt8 *gScreenBase;
  63.     // The base of the main screen buffer.
  64.     
  65. static ByteCount gRowBytes;
  66.     // The rowbytes for the main screen buffer.
  67.  
  68. static UInt16 gBytesPerChar;
  69.     // The number of bytes in a scanline that each character consumes.
  70.     // This is equivalent to the bit depth.  For example, in B&W mode,
  71.     // this is 1 (8 pixels across, at 1 bit per pixel), and in 8 bit mode
  72.     // this is 8 (8 pixels across, at 8 bits per pixel).
  73.  
  74. static ByteCount gCurrentCharIndex;
  75.     // The index of the next slot where a character will be
  76.     // plotted on the screen.  This is always manipulated by
  77.     // atomic routines, which guarantees interrupt safety.
  78.     // It wraps around freely, so must be MODed by kISDebugMaxCharIndex
  79.     // to get the actual placement.
  80.  
  81. /////////////////////////////////////////////////////////////////////
  82.  
  83. #if GENERATINGPOWERPC
  84.  
  85.     extern UInt32 AddAtomicForNonDSL(UInt32 amount, UInt32 *value);
  86.         // This routine is used only if DriverServicesLib is not
  87.         // available.
  88.  
  89. #endif
  90.  
  91. static UInt32 AddAtomicCompat(UInt32 amount, UInt32 *value)
  92.     // This routine is a standard "atomic add" function.
  93.     // It has two purposes:
  94.     // 1. It adapts AddAtomic to work with unsigned numbers.
  95.     // 2. It binds to correct AddAtomic (DSL on modern machines,
  96.     //    custom on pre-PCI machines).
  97.     // 3. It uses the OTAtomicAdd on 68K, munging the result
  98.     //      to match the behaviour of AddAtomic.
  99. {
  100.     #if GENERATING68K
  101.         // OTAtomicAdd32 is declared inline in "OpenTransport.h",
  102.         // so you can use it regardless of whether OT is installed,
  103.         // and without calling InitOpenTransport.
  104.         return OTAtomicAdd32((SInt32) amount, (SInt32 *) value) - amount;
  105.     #else
  106.         if ( false && AddAtomic == (void *) kUnresolvedCFragSymbolAddress) {
  107.             return AddAtomicForNonDSL(amount, value);
  108.         } else {
  109.             return AddAtomic((SInt32) amount, (SInt32 *) value);
  110.         }
  111.     #endif
  112. }
  113.  
  114. /////////////////////////////////////////////////////////////////////
  115.  
  116. static void PlotChar(UInt8 thisChar, ByteCount thisCharIndex)
  117. {
  118.     UInt8 *charStart;
  119.     ByteCount scanLine;
  120.     ByteCount row;
  121.     ByteCount col;
  122.     UInt8 ch;
  123.     ByteCount pixel;
  124.     
  125.     MoreAssertQ(thisCharIndex < kISDebugMaxCharIndex);
  126.  
  127.     row = thisCharIndex / kISDebugNumberOfColumns;    
  128.     col = thisCharIndex % kISDebugNumberOfColumns;
  129.     charStart = gScreenBase + row * gRowBytes * 10 + col * gBytesPerChar + kISDebugXPixelOffset + kISDebugYPixelOffset * gRowBytes;
  130.     switch (gBytesPerChar) {
  131.         case 1:
  132.             for (scanLine = 0; scanLine < 10; scanLine++) {
  133.                 *charStart = gFont[scanLine][thisChar];
  134.                 charStart += gRowBytes;
  135.             }
  136.             break;
  137.         case 4:
  138.             for (scanLine = 0; scanLine < 10; scanLine++) {                
  139.                 ch = gFont[scanLine][thisChar];
  140.                 for (pixel = 0; pixel < 8; pixel++) {
  141.                     if (ch & 0x080) {
  142.                         charStart[pixel / 2] |= (pixel % 2) ? 0x0F : 0xF0;
  143.                     } else {
  144.                         charStart[pixel / 2] &= (pixel % 2) ? 0xF0 : 0x0F;
  145.                     }
  146.                     ch = ch << 1;
  147.                 }
  148.                 charStart += gRowBytes;
  149.             }
  150.             break;
  151.         case 8:
  152.             for (scanLine = 0; scanLine < 10; scanLine++) {
  153.                 ch = gFont[scanLine][thisChar];
  154.                 for (pixel = 0; pixel < 8; pixel++) {
  155.                     if (ch & 0x080) {
  156.                         charStart[pixel] = 0xFF;
  157.                     } else {
  158.                         charStart[pixel] = 0x00;
  159.                     }
  160.                     ch = ch << 1;
  161.                 }
  162.                 charStart += gRowBytes;
  163.             }
  164.             break;
  165.         case 16:
  166.             for (scanLine = 0; scanLine < 10; scanLine++) {
  167.                 ch = gFont[scanLine][thisChar];
  168.                 for (pixel = 0; pixel < 8; pixel++) {
  169.                     if (ch & 0x080) {
  170.                         ((UInt16 *) charStart)[pixel] = 0x0000;
  171.                     } else {
  172.                         ((UInt16 *) charStart)[pixel] = 0x7FFF;
  173.                     }
  174.                     ch = ch << 1;
  175.                 }
  176.                 charStart += gRowBytes;
  177.             }
  178.             break;
  179.         case 32:
  180.             for (scanLine = 0; scanLine < 10; scanLine++) {
  181.                 ch = gFont[scanLine][thisChar];
  182.                 for (pixel = 0; pixel < 8; pixel++) {
  183.                     if (ch & 0x080) {
  184.                         ((UInt32 *) charStart)[pixel] = 0x00000000;
  185.                     } else {
  186.                         ((UInt32 *) charStart)[pixel] = 0x00FFFFFF;
  187.                     }
  188.                     ch = ch << 1;
  189.                 }
  190.                 charStart += gRowBytes;
  191.             }
  192.             break;
  193.         default:
  194.             // do nothing
  195.             break;
  196.     }
  197. }
  198.  
  199. extern void ISDebugChar(UInt8 ch)
  200.     // See comment in interface part.
  201. {
  202.     ISDebugText(&ch, sizeof(ch));
  203. }
  204.  
  205. extern void ISDebugText(const UInt8 *text, ByteCount len)
  206.     // See comment in interface part.
  207. {
  208.     UInt32 lastCharIndex;
  209.  
  210.     // For interrupt-safeness, it's critical that this add be
  211.     // atomic.
  212.         
  213.     lastCharIndex = AddAtomicCompat(len + 2, &gCurrentCharIndex) + len + 2;
  214.  
  215.     // Plotting this bullet is not 100% interrupt safe (we're assuming
  216.     // that an interrupt hasn't come in between the AddAtomic and the plot
  217.     // and written text which the bullet is going to overwrite) but it's
  218.     // sufficiently useful in helping you find the last logged text
  219.     // that I'm prepared to accept the uncertainty.
  220.     
  221.     PlotChar('•', lastCharIndex % kISDebugMaxCharIndex);
  222.     lastCharIndex -= 1;
  223.     
  224.     PlotChar('»', lastCharIndex % kISDebugMaxCharIndex);
  225.     while (len != 0) {
  226.         len -= 1;
  227.         lastCharIndex -= 1;
  228.         PlotChar(text[len], lastCharIndex % kISDebugMaxCharIndex);
  229.     }
  230.     lastCharIndex -= 1;
  231.     PlotChar('«', lastCharIndex % kISDebugMaxCharIndex);
  232. }
  233.  
  234. extern void ISDebugStr (ConstStr255Param str)
  235.     // See comment in interface part.
  236. {
  237.     ISDebugText(&str[1], str[0]);
  238. }
  239.  
  240. static ByteCount MyStrLen(const char * str)
  241.     // Include my own strlen function because I want to avoid
  242.     // linking with standard C libraries.
  243. {
  244.     ByteCount len = -1;
  245.     do {
  246.         len++;
  247.     } while (*str++);    
  248.     return(len);
  249. }
  250.  
  251. extern void ISdebugstr (const char *str)
  252.     // See comment in interface part.
  253. {
  254.     ISDebugText( (UInt8 *) str, MyStrLen(str));
  255. }
  256.  
  257. /////////////////////////////////////////////////////////////////////
  258.  
  259. enum {
  260.     kTestForColourQuickDraw = true
  261.         // You might want set this if, for example, your
  262.         // compiling in an environment where a) you know
  263.         // you have Colour QuickDraw and b) touching "qd"
  264.         // is causing link errors.
  265. };
  266.  
  267. static Boolean HasColourQuickDraw(void)
  268.     // A standard test routine.  Note that you should
  269.     // always test using the gestaltQuickdrawVersion, not
  270.     // gestaltQuickdrawFeatures, because the latter
  271.     // lies on a PB100 running System 7.0 or higher.
  272. {
  273.     UInt32 response;
  274.     
  275.     return Gestalt(gestaltQuickdrawVersion, (SInt32 *) &response) == noErr &&
  276.             response >= gestaltOriginalQD;
  277. }
  278.  
  279. extern OSStatus InitInterruptSafeDebug(void)
  280. {
  281.     OSStatus err;
  282.     Rect bounds;
  283.  
  284.     err = noErr;
  285.     
  286.     if ( kTestForColourQuickDraw && HasColourQuickDraw() ) {
  287.         PixMapHandle mainDevPM;
  288.     
  289.         mainDevPM = (**GetMainDevice()).gdPMap;
  290.  
  291.         // PixelSize is in bits, multiply by 8 for the number of pixels
  292.         // each character is across, divided by 8 to get bytes.
  293.  
  294.         gBytesPerChar = (**mainDevPM).pixelSize * 8 / 8;
  295.         gScreenBase = (UInt8 *) GetPixBaseAddr(mainDevPM);
  296.         gRowBytes = ((**mainDevPM).rowBytes) & 0x3FFF;        
  297.         bounds = (**mainDevPM).bounds;
  298.         
  299.         // If we're running on a machine with 24 bit addressing
  300.         // but the pixmap requires 32 bit addressing to access,
  301.         // spit out an error.  I'm too lazy to handle this weird
  302.         // case in my blitters.
  303.         
  304.         if ( GetMMUMode() == false32b && PixMap32Bit(mainDevPM) ) {
  305.             err = -4;
  306.         }
  307.     } else {
  308.         gBytesPerChar = 1;
  309.         gScreenBase = (UInt8 *) qd.screenBits.baseAddr;
  310.         gRowBytes = qd.screenBits.rowBytes;
  311.         bounds = qd.screenBits.bounds;
  312.     }
  313.  
  314.     if ( (bounds.right - bounds.left) < kISDebugNumberOfColumns * 8 + kISDebugXPixelOffset ) {
  315.         err = -1;
  316.     }
  317.     if ( (bounds.bottom - bounds.top) < kISDebugNumberOfRows   * 10 + kISDebugYPixelOffset ) {
  318.         err = -2;
  319.     }
  320.     switch (gBytesPerChar) {
  321.         case 1:
  322.         case 4:
  323.         case 8:
  324.         case 16:
  325.         case 32:
  326.             break;
  327.         default:
  328.             // Everything else is left as an exercise for the reader.
  329.             err = -3;
  330.             break;
  331.     }
  332.             
  333.     return err;
  334. }
  335.